#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 4e5+5;
int n;
namespace sub1{
	int a[N],cnt; 
	inline void main()
	{
		while(n--)
		{
			int x;
			cin>>x;
			int p = cnt+1;
			for(int i = 1;i<=cnt;i++)
				if(a[i]>=x)
				{
					p = i;
					break;
				}
			if(a[p]==x)
			{
				for(int i = p;i<=cnt;i++) a[i] = a[i+1];
				cnt--;
			}
			else
			{
				for(int i = cnt;i>=p;i--) a[i+1] = a[i];
				a[p] = x,cnt++;
			}
			int mn = 0,mx = -1,lt = 0,rt = 0,ans = 0;
	//		for(int i = 1;i<=cnt;i++) cout<<a[i]<<' ';
	//		cout<<"\n";
			for(int i = 1;i<=cnt;i++)
			{
				mn+=a[i],mx+=a[cnt-i+1];
	//			cout<<mn<<' '<<mx<<'\n';
				if(mn<=mx)
				{
					if(mn<=rt) ans+=mx-rt,rt = mx;
					else ans+=mx-mn+1,lt = mn,rt = mx;
				}
			}
			cout<<ans<<'\n';
		}
	}
}
namespace sub2{
	set<int> s;
	int sum;
	inline void main()
	{
		while(n--)
		{
			int x;
			cin>>x;
			if(s.count(x)) s.erase(x),sum-=x;
			else s.insert(x),sum+=x;
			if(s.size()<=1)
			{
				cout<<"0\n";
				continue;
			}
			int mn = sum,mx = sum-1,ans = 0;
			bool fl = 0;
			auto p1 = --s.end(),p2 = s.begin();
			while(p2!=s.end())
			{
				int las = mn,_las = mx,len = mx-mn+1;
				mn-=*p1,mx-=*p2;
				p1--,p2++;
				if(las>_las) continue;
				if(las>mx) ans+=len;
				else
				{
					ans+=_las-*(s.begin())+1;
					fl = 1;
					break;
				} 
			}
			if(!fl) ans+=mx-mn+1;
			cout<<ans<<'\n';
		}
	}
}
signed main()
{
	freopen("kte.in","r",stdin);
	freopen("kte.out","w",stdout);
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin>>n;
	if(n<=3e4) sub1::main();
	else sub2::main();
	return 0;
}

